<?php
namespace Logic\System;
use Spartan\Lib\Logic;

defined('APP_PATH') OR exit('404 Not Found');

class Tpl extends Logic{
	/**
	 * 读取当前的需要的发送模版
	 * @return array
	 */
	public function getTpl(){
		static $arrTpl = Array();
		$strTplKey = $this->getData('tpl_key','');
		if (!$strTplKey) {
			return Array('发送模版KEY不能为空。',0);
		}
		!isset($arrTpl[$strTplKey]) && $arrTpl[$strTplKey] = $this->_findTpl();
		return isset($arrTpl[$strTplKey])?$arrTpl[$strTplKey]:[];
	}

	/**
	 * 查询一条模版记录
	 * @return array
	 */
	private function _findTpl(){
		$strTplKey = $this->getData('tpl_key','');
		$options = Array(//找到队列需要的模版
             'where'=>Array(
                 'key'=>$strTplKey,
                 'status'=>1,
             ),
		);
		$arrInfo = $this->Db()->find('system_message_tpl',$options);
		if (!$arrInfo){
			return Array("发送模版{$strTplKey}不存在。",0);
		}
		$arrInfo['mobile_info'] = htmlspecialchars_decode($arrInfo['mobile_info']);
		$arrInfo['message_info'] = htmlspecialchars_decode($arrInfo['message_info']);
		$arrInfo['email_info'] = htmlspecialchars_decode($arrInfo['email_info']);
		return Array('success',($arrInfo===false?0:1),$arrInfo);
	}

} 